document.write('<link href="../common/css/StyleReport.css" rel="stylesheet" type="text/css" />');
document.write('<link href="../common/css/defaultTheme.css" rel="stylesheet" type="text/css" />');
document.write('<link href="../common/css/myTheme.css" rel="stylesheet" type="text/css" />');
document.write('<link href="../common/css/window.css" type="text/css" rel="stylesheet" />');
document.write('<script src="../common/js/formsubmit.js"></script>');


function compareDateStr(sdate, edate){
	return Date.parse(edate) - Date.parse(sdate);
}
function date2str(date, flag){
        flag="/";
	if(date.getFullYear()>0)
	return date.getFullYear()+flag+((date.getMonth()+1)<10?'0':'')+(date.getMonth()+1)+flag+(date.getDate()<10?'0':'')+date.getDate();
	else return '';
}

function str2date(str){
	var tok = str.split(/[\/\-]/);
	y1 = parseInt(tok[0],10);
	m1 = parseInt(tok[1],10);
	d1 = parseInt(tok[2],10);
	return new Date(m1+'/'+d1+'/'+y1);
}
function isDateStr(testDate){
	try{
		var tok = testDate.split(/[\/\-]/);
		y1 = parseInt(tok[0],10);
		m1 = parseInt(tok[1],10);
		d1 = parseInt(tok[2],10);
		var date = new Date(m1+'/'+d1+'/'+y1);
		y2 = date.getFullYear();
		m2 = date.getMonth()+1;
		d2 = date.getDate();
		return y1==y2 && m1==m2 && d1==d2;
	} catch(err){
		return false;
	}
}
function postHandler(url, para, callBack, errCallBack){
	togglemask(true);
	$.ajax({
	  type: "POST",
	  url: url,
	  data: para,
	  success: function(msg){
		 if(callBack) {
			 callBack(msg);
			 setTimeout('togglemask(false);',300);
		 }else
			 togglemask(false);
      },
	  error: function(a,b,c){
    	  togglemask(false);
        if(errCallBack) errCallBack(c);
		else {
                  // alert('重新整理');
                  // location.reload();
                };
      }
	});
}
function getHandler(url, para, callBack, errCallBack){
	$.ajax({
	  type: "GET",
	  url: url,
	  data: para,
	  success: function(msg){
		 if(callBack) {
			 callBack(msg);
			// setTimeout('togglemask(false);',300);
		 }else{
			// togglemask(false);
                 }
      },
	  error: function(a,b,c){
    	 
        if(errCallBack) errCallBack(c);
		else {
                   //alert('重新整理');
                   //location.reload();
                };
      }
	});
}
function initChkbox(){
	$('input:checkbox').each(function(){
		var oDiv = $(this).closest('div');
		if(oDiv.find('input:checkbox').length>1){
			$(this).parent().attr('hasChildren',true);
		}
	});
	$('input:checkbox').change(function(){
		var chk = $(this)[0].checked;
		var oDiv = $(this).closest('div');
		if(oDiv.parent().hasClass('checkbox_box_w')) oDiv = oDiv.parent();
		oDiv.find('input:checkbox').each(function(){$(this)[0].checked = chk;});
		if(!oDiv.hasClass('checkbox_box_w')){
			var oParent = oDiv.closest('.checkbox_box').parent();
			var oChks = oDiv.parent().find('input:checkbox');
			var pChg = true;
			for(var i=0;i<oChks.length;i++)
				if(chk!=oChks.eq(i)[0].checked) pChg = false;
			pChg = chk?chk:pChg;
			//if(pChg) oParent.find('input:checkbox').eq(0)[0].checked = chk;
		}
	});
}
function initPopupWindow() {
	$('a.window').click(function() {
		var loginBox = $(this).attr('href');
		$(loginBox).fadeIn(300);
		 
		var popMargTop = ($(loginBox).height() - 150) / 2; 
		var popMargLeft = ($(loginBox).width() -0 ) / 2; 
		
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		$('#mask').click(function() { 
			  $('a.close').click();
        });
		return false;
	});
	$('a.close , .cancel').bind('click', function() { 
			  $('#mask , .window-popup').fadeOut(300 , function() {
				$('#mask').remove();  
			  }); 
			  return false;
    });
}
function getRadioVal(name){
	 var oRadio = $('input[name='+name+']:radio');
	 for(var i=0;i<oRadio.length;i++){
		 if(oRadio.eq(i)[0].checked==true) return oRadio.eq(i).val();
	 }
	 return '';
}
function getDateRange(date, type, flag){
	var begin,end;
        flag="/";
	if(type=='month' || type=='year'){
		begin = new Date(date.getFullYear(), type=='month'?date.getMonth():0, 1);
		end = new Date(date.getFullYear(), type=='month'?date.getMonth()+1:12, 0);
	}else{
		begin = date;
		begin.setDate(begin.getDate()+1-(begin.getDay()||7));
		end = new Date(begin.getTime());
		end.setDate(end.getDate() + 6);
	}
        //console.log("begin.getMonth():"+begin.getMonth());
	var range = begin.getFullYear()+flag+(begin.getMonth()<9?'0':'')+(begin.getMonth()+1)+flag+(begin.getDate()<9?'0':'')+begin.getDate()+' ~ '+
	end.getFullYear()+flag+(end.getMonth()<9?'0':'')+(end.getMonth()+1)+flag+(end.getDate()<9?'0':'')+end.getDate();
	return range;
	
}
function togglemask(show) {
	if(show){
		$('body').addClass('loading');
		$('body').append('<div class="modal"><img src="../common/images/loading.gif?r'+new Date().getTime()+'" style="position:fixed;top:50%;left:50%;"/></div>');
	}else{
		$('.modal').remove();
		$('body').removeClass('loading');
	}
}